package com.ruoyi.weixin.shop.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.weixin.shop.domain.vo.WxShareAddBo;
import com.ruoyi.weixin.shop.domain.vo.WxShareEditBo;
import com.ruoyi.weixin.shop.domain.vo.WxShareQueryBo;
import com.ruoyi.weixin.shop.domain.vo.WxShareVo;
import com.ruoyi.weixin.shop.service.IWxShareService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 微信商城分享Controller
 * @author ruoyi
 * @date 2021-07-12
 */
@Api(value = "微信商城分享控制器", tags = {"微信商城分享管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/shop/share")
public class WxShareController extends BaseController {

	private final IWxShareService iWxShareService;

	/**
	 * 查询微信商城分享列表
	 */
	@ApiOperation("查询微信商城分享列表")
	@PreAuthorize("@ss.hasPermi('system:share:list')")
	@GetMapping("/list")
	public TableDataInfo<WxShareVo> list(@Validated WxShareQueryBo bo) {
		return iWxShareService.queryPageList(bo);
	}

	/**
	 * 导出微信商城分享列表
	 */
	@ApiOperation("导出微信商城分享列表")
	@PreAuthorize("@ss.hasPermi('system:share:export')")
	@GetMapping("/export")
	public AjaxResult<WxShareVo> export(@Validated WxShareQueryBo bo) {
		List<WxShareVo> list = iWxShareService.queryList(bo);
		ExcelUtil<WxShareVo> util = new ExcelUtil<WxShareVo>(WxShareVo.class);
		return util.exportExcel(list, "微信商城分享");
	}

	/**
	 * 获取微信商城分享详细信息
	 */
	@ApiOperation("获取微信商城分享详细信息")
	@PreAuthorize("@ss.hasPermi('system:share:query')")
	@GetMapping("/{id}")
	public AjaxResult<WxShareVo> getInfo(@NotNull(message = "主键不能为空")
										 @PathVariable("id") Long id) {
		return AjaxResult.success(iWxShareService.queryById(id));
	}

	/**
	 * 新增微信商城分享
	 */
	@ApiOperation("新增微信商城分享")
	@PreAuthorize("@ss.hasPermi('system:share:add')")
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody WxShareAddBo bo) {
		return toAjax(iWxShareService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改微信商城分享
	 */
	@ApiOperation("修改微信商城分享")
	@PreAuthorize("@ss.hasPermi('system:share:edit')")
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody WxShareEditBo bo) {
		return toAjax(iWxShareService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除微信商城分享
	 */
	@ApiOperation("删除微信商城分享")
	@PreAuthorize("@ss.hasPermi('system:share:remove')")
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iWxShareService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
	}
}
